package com.video.ui.manage;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import com.google.android.material.snackbar.Snackbar;
import com.video.R;

public class ManageFragment extends Fragment {

//    private ManageViewModel manageViewModel;
    private static SharedPreferences sp;
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//        manageViewModel = new ViewModelProvider(this).get(ManageViewModel.class);
        View root = inflater.inflate(R.layout.fragment_manage, container, false);
        sp = requireContext().getSharedPreferences("data", Context.MODE_PRIVATE);
        EditText ip=root.findViewById(R.id.ipAddress);
        EditText port=root.findViewById(R.id.port);
        EditText dir=root.findViewById(R.id.dir);
        ip.setText(sp.getString("ip","10.147.17.1"));
        port.setText(sp.getString("port","8000"));
        dir.setText(sp.getString("dir","/"));
        root.findViewById(R.id.save).setOnClickListener(v -> {
            SharedPreferences.Editor edit = sp.edit();
            edit.putString("ip",ip.getText().toString());
            edit.putString("port",port.getText().toString());
            edit.putString("dir",dir.getText().toString());
            edit.apply();
            Snackbar.make(root,"已保存",Snackbar.LENGTH_SHORT).show();
        });



        return root;
    }
}